<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
    <style>
        html {
            background-color: #fff;
            color: #666;
        }
    </style>
</head>
<body>

<div class="layui-card-body">
    <form class="layui-form" action="" lay-filter="component-form-element">
        <div class="layui-form-item">
            <label class="layui-form-label">网站名称</label>
            <div class="layui-input-block">
                <input type="text" name="siteName" value="" lay-verify="required" placeholder="网站名称，如：北京某某科技有限公司" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">二级域名</label>
            <div class="layui-input-block">
                <div class="layui-input-inline" style="width: 80px;">
                    <input type="text" name="domain" id="domain" lay-verify="required" value="${site.domain!}" class="layui-input">
                </div>
                <div class="layui-input-inline layui-input-company">.97560.com</div>
                <div class="text-tips" id="domain-tips">PC端可通过浏览器访问。</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="禁用">
                <input type="radio" name="status" value="1" title="启用" checked>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
        </div>
    </form>
</div>
<script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
<script>
    layui.config({
        base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,form = layui.form;

        form.render(null, 'component-form-element');
        element.render('breadcrumb', 'breadcrumb');

        form.on('submit(component-form-element)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });

        //查询二级域名状态
        $("#domain").on("blur", function(){
            var domain=$("#domain").val();
            var siteId=$("#id").val();
            if(domain.length>0){
                if(/^[0-9a-zA-Z]*$/.test(domain)){
                    $.ajax({
                        url:'/member/site/queryDomain.do',
                        type:'post',
                        dataType: 'json',
                        data: {"domain":domain,"siteId":siteId},
                        success:function(e){
                            if (e.code == "0") {
                                $("#domain-tips").html("可通过这个二级域名访问您的网站");
                                $(this).closest('div').removeClass('has-error').addClass('has-success');
                            }else {
                                $("#domain-tips").html(e.message);
                                $(this).closest('div').removeClass('has-success').addClass('has-error');
                            }
                        }
                    })
                }else{
                    $("#domain-tips").html("二级域名格式不对");
                    $(this).closest('div').removeClass('has-success').addClass('has-error');
                }
            }else{
                $("#domain-tips").html("二级域名不能为空");
                $(this).closest('div').removeClass('has-success').addClass('has-error');
            }
        });

        form.on('submit(addsite)', function(data) {
            $.ajax({
                url:'/member/site/add.do',
                type:'post',
                dataType: 'json',
                data: data.field,
                success:function(e){
                    if (e.code == "0") {
                        layer.msg('成功');
                        window.location.reload();
                    }else {
                        layer.msg('失败');
                    }
                }
            })
            //防止页面跳转
            return false;
        });
    });
</script>
</body>
</html>